package com.woniuxy.yoga.admin.web.controller;


import ch.qos.logback.core.rolling.helper.IntegerTokenConverter;
import com.woniuxy.yoga.admin.dao.model.AdminRole;
import com.woniuxy.yoga.admin.permission.Permission;
import com.woniuxy.yoga.admin.service.AdminRoleService;
import com.woniuxy.yoga.commons.core.model.Result;
import com.woniuxy.yoga.commons.web.log.YogaLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 管理员角色表 前端控制器
 * </p>
 *
 * @author 韦用文,刘存益,郎腾霄
 * @since 2023年11月28日
 */
@RestController
@RequestMapping("/adminRole")
@Api(tags = "管理员角色相关接口")
public class AdminRoleController {

    @Autowired
    private AdminRoleService adminRoleService;

    /**
     * 根据账号ID查询管理员角色
     * @param accountId
     * @return
     */
    @GetMapping("/selectRoleByAccountId/{accountId}")
    @ApiOperation("根据账号ID查询管理员角色")
    @YogaLog("根据账号ID查询管理员角色")
    public Result<AdminRole> selectRoleByAccountId(@PathVariable("accountId")Integer accountId){
        AdminRole adminRole = adminRoleService.selectRoleByAccountId(accountId);
        return Result.getResult(AdminRole.class).setData(adminRole).setMessage("查询管理员角色成功");
    }

    /**
     * 查询所有存在的角色
     */
    @GetMapping("/selectAllRole.api")
    @ApiOperation("查询所有存在的角色")
    @YogaLog("查询所有存在的角色")
    @Permission(resources = {"/admin/adminRole/selectAllRole.api"})
    public Result<List<AdminRole>> selectAllRole(){
        List<AdminRole> adminRoles = adminRoleService.list();
        return Result.getListResult(AdminRole.class).setMessage("查询所有角色成功").setData(adminRoles);
    }

}

